module.exports = {
  router: {
    linkActiveClass: 'active',
    // 自定义路由表规则
    extendRoutes(routes, resolve) {
      // 其实 routes 就是一个数组
      // console.log(routes)
      // routes.push({
      //   name: 'custom',
      //   path: '*',
      //   component: resolve(__dirname, 'pages/404.vue')
      // })

      // 清除 Nuxt.js 基于目录默认生成的路由表规则
      routes.splice(0);

      routes.push(
        ...[
          {
            path: '/',
            // 此时 /layout/ 已经不能访问，已经变成 /
            // 不用 index.vue 作为首页，因为不方便组织组件
            component: resolve(__dirname, 'pages/layout/'),
            children: [
              {
                path: '', // 默认子路由
                name: 'home',
                component: resolve(__dirname, 'pages/home/'),
              },
              // 为了简易，把注册和登录写到了一起
              {
                path: '/login',
                name: 'login',
                component: resolve(__dirname, 'pages/login/'),
              },
              {
                path: '/register',
                name: 'register',
                component: resolve(__dirname, 'pages/login/'),
              },
              {
                path: '/profile/:username',
                name: 'profile',
                component: resolve(__dirname, 'pages/profile/'),
              },
              {
                path: '/settings',
                name: 'settings',
                component: resolve(__dirname, 'pages/settings/'),
              },
              {
                path: '/editor',
                name: 'editor',
                component: resolve(__dirname, 'pages/editor/'),
              },
              {
                path: '/article/:slug',
                name: 'article',
                component: resolve(__dirname, 'pages/article/'),
              },
            ],
          },
        ]
      );
    },
  },

  server: {
    // 监听所有网卡地址
    // 本地就使用 localhost
    host: '0.0.0.0',
    // 根据需要修改端口号
    port: 3000,
  },

  // 注册插件
  plugins: ['~/plugins/request.js', '~/plugins/dayjs.js'],
};
